var mongoose=require('mongoose');
var User=mongoose.model('User',{
    name:String,
    number:Number,
    winner:Boolean
});
var db=mongoose.connect('mongodb://localhost/MongoDB_QuanWei_2');


User.update({name:'A'},{number:1101,winner:true},{upsert:true},(e,r)=>{
    if(e)throw e;
    console.log('Update:\n',r);

    User.update({name:'B'},{number:1202,winner:false},{upsert:true},(e,r)=>{
        if(e)throw e;
        console.log('Update:\n',r);


        User.update({name:'C'},{number:1303,winner:true},{upsert:true},(e,r)=>{
            if(e)throw e;
            console.log('Update:\n',r);

            User.update({name:'D'},{number:1404,winner:false},{upsert:true},(e,r)=>{
                if(e)throw e;
                console.log('Update:\n',r);

                User.find({

                    number:{
                        $not:{
                            $in:[1101,1202]
                        }
                    }

                },(e,r)=>{
                    if(e)throw e;
                    console.log('\nFind:\n',JSON.stringify(r,null,2));
                    process.exit(1);
                });


            });

        });

    });

});


/*
* {field:{$mod:[除数，余数]}
*
* 匹配field值取模运算结果
* */
